<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        /*
            访问器属性：
                - get:当访问对象的属性的时候，就会调用get属性对应的函数
                - set:当给对象设置属性的时候，就会调用set属性对应的函数
        */
        var o = {
            firstName:"laowang",
            lastName:"SB"
        }
        Object.defineProperty(o,"fullName",{
            get:function(){
                return(this.firstName + this.lastName);
            },
            set:function(val){
                console.log("接收到的参数",val);
                
                //把接收到的参数依次设置给属性值
                let newarr = val.split(" ");
                this.firstName = newarr[0];
                this.lastName = newarr[1];
            }
        })
        console.log(o.fullName);
        
        //给访问器对象设置属性值
        o.fullName = "lao li";
        console.log(o);
    </script>
</body>
</html>